import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/modules/widget/app_bar_widget.dart';
import 'package:earclean/app/modules/widget/login_button.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/pay_controller.dart';

class PayView extends GetView<PayController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const AppBarWidget(
          backgroundColor: ColorConfig.white, titleStr: '订单支付'),
      body: Column(
        children: [
          // MyWidget(),
          SizedBox(height: 10),
          Container(
            color: ColorConfig.white,
            padding: EdgeInsets.symmetric(vertical: 8),
            width: 1.sw,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('剩余支付时间：',
                    style: TextStyle(
                      fontSize: 15.sp,
                      color: ColorConfig.text_label,
                    )),
                Text('10分10秒',
                    style: TextStyle(
                      fontSize: 15.sp,
                      color: Colors.red,
                    )),
              ],
            ),
          ),
          SizedBox(height: 60),
          Text('支付',
              style: TextStyle(
                fontSize: 18.sp,
                color: ColorConfig.text_label,
                fontWeight: FontWeight.bold,
              )),
          SizedBox(height: 10),
          Obx(() => Text('${controller.price}元',
              style: TextStyle(
                fontSize: 16.sp,
                color: Colors.red,
                fontWeight: FontWeight.bold,
              ))),
          SizedBox(height: 60),
          Container(
            width: 1.sw,
            padding: EdgeInsets.symmetric(horizontal: 18),
            child: Text('支付方式',
                style: TextStyle(
                  fontSize: 16.sp,
                  color: ColorConfig.text_label,
                )),
          ),
          SizedBox(height: 20),

          Obx(() => Offstage(
                offstage: controller.showWx.value == false,
                child: InkWell(
                    onTap: () {
                      controller.paytype.value = 2;
                    },
                    child: cellWidget('assets/images/wx.png', '微信支付')),
              )),
          SizedBox(height: 10),
          Obx(() => Offstage(
                offstage: controller.showZfb.value == false,
                child: InkWell(
                    onTap: () {
                      controller.paytype.value = 1;
                    },
                    child: cellWidget1('assets/images/zfb.png', '支付宝')),
              )),
          SizedBox(height: 60),
          Obx(() => (controller.showZfb.value == false &&
                  controller.showWx.value == false)
              ? Container()
              : Container(
                  width: 1.sw,
                  height: 45,
                  margin: EdgeInsets.symmetric(horizontal: 30.w),
                  child: LoginButton(
                    "确定",
                    enable: true,
                    onPressed: () {
                      controller.pay();
                    },
                  ),
                )),
        ],
      ),
    );
  }

  Widget cellWidget(String img, String title) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 18),
      padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(10.r)),
      ),
      child: Row(
        children: [
          Image.asset(
            img,
            width: 40.r,
            height: 40.r,
          ),
          SizedBox(
            width: 15.w,
          ),
          Text(title,
              style: TextStyle(
                  fontSize: 15.sp,
                  color: ColorConfig.body1_txt_color,
                  fontWeight: FontWeight.w400)),
          const Spacer(),
          Obx(() => Image.asset(
                controller.paytype.value == 2
                    ? 'assets/images/aaa.png'
                    : 'assets/images/111.png',
                width: 20,
              )),
        ],
      ),
    );
  }

  Widget cellWidget1(String img, String title) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 18),
      padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(10.r)),
      ),
      child: Row(
        children: [
          Image.asset(
            img,
            width: 40.r,
            height: 40.r,
          ),
          SizedBox(
            width: 15.w,
          ),
          Text(title,
              style: TextStyle(
                  fontSize: 15.sp,
                  color: ColorConfig.body1_txt_color,
                  fontWeight: FontWeight.w400)),
          const Spacer(),
          Obx(() => Image.asset(
                controller.paytype.value == 1
                    ? 'assets/images/aaa.png'
                    : 'assets/images/111.png',
                width: 20,
              )),
        ],
      ),
    );
  }
}

class MyWidget extends StatefulWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> with WidgetsBindingObserver {
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        print('查询支付专题');

        break;
      default:
    }
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
